<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="款式编码">
              <a-input placeholder="请输入款式编码" v-model="queryParam.codeNum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="胶膜号">
              <a-input placeholder="请输入胶膜号" v-model="queryParam.modelNum"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="名称">
                <a-input placeholder="请输入名称" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="所属客户">
                <j-dict-select-tag placeholder="请选择所属客户" v-model="queryParam.customer" dictCode="customer_info,cus_name,cus_name"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('款式资料')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
    </div>


    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px;" @click="onClearSelected">清空</a>
        <a style=" margin-right: 30px; float: right; " @click='changeView(1)' ><a-icon type="bars"/>列表</a>
        <a style=" margin-right: 10px; float: right; " @click='changeView(2)'><a-icon type="appstore"/>网格</a>
      </div>
      <div class="card-list" ref="content" v-show='isGridShow' >
      <a-list
        id='grid_list'
        :grid="{gutter: 24, lg: 3, md: 2, sm: 1, xs: 1}"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        >
        <a-list-item slot="renderItem" slot-scope="item, index" >
          <template >
            <a-card :hoverable="true"  @click="cardClickThenSelect(item)"    :style= 'item.id===selectedId ? selectedStyle : defaultStyle' >
              <a-card-meta >
                <div style="margin-bottom: 3px" slot="title">{{ item.name }}</div>
                <a-avatar class="card-avatar" slot="avatar" :src="getImgView(item.styleImageString)" size="large"/>
                <div class="meta-content" slot="description">{{ item.codeNum }}</div>
              </a-card-meta>
              <!--记录操作按钮 开始-->

              <template class="ant-card-actions" slot="actions">
                <a @click="handleEdit(item)">编辑</a>
                                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(item.id)">
                                  <a>删除</a>
                                </a-popconfirm>
              </template>
              <!--记录操作按钮 结束-->
            </a-card>
          </template>
        </a-list-item>
      </a-list>
      </div>

      <a-table
        id='table_list'
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
        :customRow="clickThenSelect"
        @change="handleTableChange"
        v-show='isTableShow'

      >

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text" >
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic; ">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="套件资料" key="1" >
        <StyleSuitInfoList :mainId="selectedMainId" />
      </a-tab-pane>
      <a-tab-pane tab="工序资料" key="2" forceRender>
        <StyleWorkingProcedureList :mainId="selectedMainId" />
      </a-tab-pane>
      <a-tab-pane tab="配石资料" key="3" forceRender>
        <StyleStoneInfoList :mainId="selectedMainId" />
      </a-tab-pane>
      <a-tab-pane tab="配件资料" key="4" forceRender>
        <StyleAccessoryInfoList :mainId="selectedMainId" />
      </a-tab-pane>
      <a-tab-pane tab="电镀资料" key="5" forceRender>
        <StyleElectroplateInfoList :mainId="selectedMainId" />
      </a-tab-pane>
      <a-tab-pane tab="其他资料" key="6" forceRender>
        <StyleOtherInfoList :mainId="selectedMainId" />
      </a-tab-pane>
    </a-tabs>

    <styleInfo-modal ref="modalForm" @ok="modalFormOk"></styleInfo-modal>
  </a-card>
</template>



<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import StyleInfoModal from './modules/StyleInfoModal'
  import { getAction } from '@/api/manage'
  import StyleSuitInfoList from './StyleSuitInfoList'
  import StyleWorkingProcedureList from './StyleWorkingProcedureList'
  import StyleStoneInfoList from './StyleStoneInfoList'
  import StyleAccessoryInfoList from './StyleAccessoryInfoList'
  import StyleElectroplateInfoList from './StyleElectroplateInfoList'
  import StyleOtherInfoList from './StyleOtherInfoList'
  import {initDictOptions,filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import '@/assets/less/TableExpand.less'

  import {
    TableOutlined,
    HomeOutlined,
    SettingFilled,
    SmileOutlined,
    SyncOutlined,
    LoadingOutlined,
  } from '@ant-design/icons'

  export default {
    name: "StyleInfoList",
    mixins:[JeecgListMixin],
    components: {
      StyleSuitInfoList,
      StyleWorkingProcedureList,
      StyleStoneInfoList,
      StyleAccessoryInfoList,
      StyleElectroplateInfoList,
      StyleOtherInfoList,
      StyleInfoModal
    },
    data () {
      return {
        isGridShow: false, //展示网格
        isTableShow: true, //展示列表
        defaultStyle:{},
        selectedStyle:{"color": "#0785fd","font-weight": "bold","border-color": "#00DB00"},
        selectedId: 0,
        description: '款式资料管理页面',
        // 表头
        columns: [
          {
            title:'款式编码',
            align:"center",
            dataIndex: 'codeNum'
          },
          {
            title:'款式分类',
            align:"center",
            dataIndex: 'styleCate_dictText',
          },
          {
            title:'胶膜号',
            align:"center",
            dataIndex: 'modelNum'
          },
          {
            title:'名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'所属客户',
            align:"center",
            dataIndex: 'customer_dictText',
          },
          {
            title:'头版金重',
            align:"center",
            dataIndex: 'goldWeight'
          },
          {
            title:'耗率',
            align:"center",
            dataIndex: 'attritionRate'
          },
          {
            title:'工费',
            align:"center",
            dataIndex: 'labourCost'
          },
          {
            title:'规格/手寸',
            align:"center",
            dataIndex: 'styleSize'
          },
          {
            title:'长度',
            align:"center",
            dataIndex: 'length'
          },
          {
            title:'宽度',
            align:"center",
            dataIndex: 'width'
          },
          {
            title:'银版重',
            align:"center",
            dataIndex: 'silverModelWeight'
          },
          {
            title:'蜡版重',
            align:"center",
            dataIndex: 'waxModelWeight'
          },
          {
            title:'难度级别',
            align:"center",
            dataIndex: 'difficultLevel'
          },
          {
            title:'单价',
            align:"center",
            dataIndex: 'unitPrice'
          },
          {
            title:'款式系列',
            align:"center",
            dataIndex: 'styleSeries'
          },
          {
            title:'生产要求',
            align:"center",
            dataIndex: 'productionRequirement'
          },
          {
            title:'起版要求',
            align:"center",
            dataIndex: 'platemakingRequirement'
          },
          {
            title:'款式图片',
            align:"center",
            dataIndex: 'styleImageString' ,
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title:'订单信息',
            align:"center",
            dataIndex: 'orderid'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/styleInfo/styleInfo/list",
          delete: "/styleInfo/styleInfo/delete",
          deleteBatch: "/styleInfo/styleInfo/deleteBatch",
          exportXlsUrl: "/styleInfo/styleInfo/exportXls",
          importExcelUrl: "styleInfo/styleInfo/importExcel",
        },
        dictOptions:{
         styleCate:[],
         customer:[],
        },
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 5,
          pageSizeOptions: ['5', '10', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        selectedMainId:'',
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      changeView(tag)
      {
        if(tag===1)   //展示列表
        {
          this.isTableShow=true;
          this.isGridShow=false;
        }
        else if(tag===2) { //展示网格
          this.isTableShow = false;
          this.isGridShow = true;
        }
      },

      cardClickThenSelect(record) {
              console.log('changeOn',record.id);
              this.onSelectChange(record.id.split(","), [record]);
              this.selectedId=record.id;
      },

      initDictConfig(){
        initDictOptions('style_type').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'styleCate', res.result)
          }
        })
        initDictOptions('customer_info,cus_name,cus_name').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'customer', res.result)
          }
        })
      },
      clickThenSelect(record) {

        return {
          on: {
            click: () => {
              console.log('changeOn',record.id);
              this.onSelectChange(record.id.split(","), [record]);
            }
          }
        }
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId=''
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        this.onClearSelected()
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'codeNum',text:'款式编码',dictCode:''})
        fieldList.push({type:'string',value:'styleCate',text:'款式分类',dictCode:'style_type'})
        fieldList.push({type:'string',value:'modelNum',text:'胶膜号',dictCode:''})
        fieldList.push({type:'string',value:'name',text:'名称',dictCode:''})
        fieldList.push({type:'string',value:'customer',text:'所属客户',dictCode:'customer_info,cus_name,cus_name'})
        fieldList.push({type:'string',value:'goldWeight',text:'头版金重',dictCode:''})
        fieldList.push({type:'string',value:'attritionRate',text:'耗率',dictCode:''})
        fieldList.push({type:'double',value:'labourCost',text:'工费',dictCode:''})
        fieldList.push({type:'string',value:'styleSize',text:'规格/手寸',dictCode:''})
        fieldList.push({type:'double',value:'length',text:'长度',dictCode:''})
        fieldList.push({type:'double',value:'width',text:'宽度',dictCode:''})
        fieldList.push({type:'double',value:'silverModelWeight',text:'银版重',dictCode:''})
        fieldList.push({type:'double',value:'waxModelWeight',text:'蜡版重',dictCode:''})
        fieldList.push({type:'string',value:'difficultLevel',text:'难度级别',dictCode:''})
        fieldList.push({type:'double',value:'unitPrice',text:'单价',dictCode:''})
        fieldList.push({type:'string',value:'styleSeries',text:'款式系列',dictCode:''})
        fieldList.push({type:'string',value:'productionRequirement',text:'生产要求',dictCode:''})
        fieldList.push({type:'string',value:'platemakingRequirement',text:'起版要求',dictCode:''})
        fieldList.push({type:'Blob',value:'styleImage',text:'款式图片',dictCode:''})
        fieldList.push({type:'string',value:'codeNumKey',text:'编码标签',dictCode:''})
        fieldList.push({type:'string',value:'orderid',text:'订单信息',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style  lang="less" scoped>
  @import '~@assets/less/common.less';
  .card-avatar {
                       width: 148px;
                       height: 148px;
                       border-radius: 48px;
                     }

  .ant-card-actions {
    background: #f7f9fa;
  li {
    float: left;
    text-align: center;
    margin: 12px 0;
    color: rgba(0, 0, 0, 0.45);
    width: 50%;

  &:not(:last-child) {
     border-right: 1px solid #e8e8e8;
   }

  a {
    color: rgba(0, 0, 0, .45);
    line-height: 22px;
    display: inline-block;
    width: 100%;
  &:hover {
     color: #1890ff;
   }
  }
  }
  }

  .new-btn {
    background-color: #fff;
    border-radius: 2px;
    width: 100%;
    height: 186px;
  }

  .meta-content {
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    height: 64px;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }
</style>